<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Save Text to File</title>
</head>
<body>
    <textarea id="inputText" rows="10" cols="50" placeholder="Enter your text here..."></textarea><br>
    <button id="saveButton">Save to File</button>

    <script>
        document.getElementById('saveButton').addEventListener('click', function() {
            // 获取用户输入的内容
            const text = document.getElementById('inputText').value;

            // 创建一个 Blob 对象
            const blob = new Blob([text], { type: 'text/plain' });

            // 创建一个可下载的链接
            const url = URL.createObjectURL(blob);

            // 创建一个 a 元素并模拟点击
            const a = document.createElement('a');
            a.href = url;
            a.download = 'output.txt'; // 设置文件名
            a.click();

            // 释放对象 URL
            URL.revokeObjectURL(url);
        });
    </script>
</body>
</html>